Mid Function

Returns a portion of a String. The first character is numbered 1.

Syntax

result = Mid( source, start, [length] )

result = stringVariable.Mid( start, [length] )


Parameters

source

String

Required. The string from which characters are returned.

start

Integer

Required. The position of the first character to be returned. The first character position is 1. If start is greater than the number of characters in source, an empty string is returned.

length (Optional)

Integer

Optional. The number of characters to return from source. If ommitted, all characters from start to the end of source are returned. If length + start is greater than the length of source, all characters from start to the end of source will be returned.



Notes

To determine the number of characters in a String, use the Len function.

The Mid function works properly with international text.


Examples

These examples use the Mid function to return portions of a String.

Dim s As String
s = Mid ("This is a test", 6) //returns "is a test"
s = Mid("This is a test", 11, 4) //returns "test"

This example converts the text string in EditField1 to hex and writes the result to EditField2:

Dim i as Integer
EditField2.text=""
For i=1 to Len(EditField1.text)
 EditField2.text=EditField2.text+"&h"+ Hex( Asc(Mid(EditField1.text,i,1)))
Next

See Also

Asc, Chr, InStr, Left, Len, Right functions.